#include "SubMenu.h"

SubMenu::SubMenu( ShapeContainer* shapeCon1, const unsigned int& index1)
	:m_shapeCon(NULL), m_index(index1), m_option(0)
{
	m_app = new Application(shapeCon1);
};

void SubMenu::selection()
{
	switch (m_option)
	{
	case 1:
		m_app->drawShapeCon();
		break;
	case 2:
		if (m_app->delShape(m_index))
			cout << "Shape deleted." << endl;
		break;
	case 3:
		if (m_app->moveShapeToFront(m_index))
			cout << "Shape moved to the front" << endl;
		break;

	case 4:
		if (m_app->moveShapeToBack(m_index))
			cout << "Shape moved to the back" << endl;
		break;

	case 5:
		if (m_app->moveShape(m_index))
			cout << "Shape has been moved" << endl;
		break;

	case 6:
		if (m_app->addAnimationToShape(m_index))
			cout << "Animation has been created" << endl;
		break;

	}
}

void SubMenu::drawMenu() const
{
	clrscr();
	cout << "1. Cancel selection" << endl;

	cout << "2. Delete shape" << endl;

	cout << "3. Move to foreground" << endl;

	cout << "4. Move to background" << endl;

	cout << "5. Move shape" << endl;

	cout << "6. Add animation" << endl;
}

bool SubMenu::legal(unsigned int option) const
{
	if (option == 1 || 
		option == 2 ||
		option == 3 ||
		option == 4 ||
		option == 5 ||
		option == 6)
		return true;
	
	return false;
}

void SubMenu::run()
{
	do
	{
		this->drawMenu();
		this->getInput();

		if (this->legal(m_option))
		{
			this->selection();
		}
		else
			cout << endl << "You have entered an incorrect selection" << endl;
		
		if (!exit())
		{
			gotoxy(0,23);
			cout << "Press any key to continue...";
			char temp = _getch();
		}

	}
	while (!exit());

}

SubMenu::~SubMenu ()
{
	delete m_app;
}